package com.test.base.vo.common;

public class ResultData<T> {
    private T data;
    private String errmsg;
    private int errno;
    //成功true 失败 false
    private boolean success;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public int getErrno() {
        return errno;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public ResultData(T data, String errmsg, boolean success) {
        this.data = data;
        this.errmsg = errmsg;
        this.success = success;
        this.errno = success == true ? 0 : 1;
    }

    public ResultData(T data) {
        this.data = data;
        this.errno = 0;
    }

    public ResultData(int errno, String errmsg) {
        this.errmsg = errmsg;
        this.errno = errno;
    }


    public static ResultData success() {
        return new ResultData(0, null);
    }

    public static ResultData success(Object data) {
        return new ResultData(data);
    }

    public static ResultData fail(String errmsg) {
        return new ResultData(400, errmsg);
    }

    public static ResultData fail(int code,String errmsg) {
        return new ResultData(code, errmsg);
    }


    @Override
    public String toString() {
        return "ResultData{" +
                "data=" + data +
                ", errmsg='" + errmsg + '\'' +
                ", errno=" + errno +
                ", success=" + success +
                '}';
    }
}
